package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.BaiSci;
import com.ruoyi.system.service.IBaiSciService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 每日科普Controller
 * 
 * @author saruri
 * @date 2024-07-18
 */
@RestController
@RequestMapping("/sci")
public class BaiSciController extends BaseController
{
    @Autowired
    private IBaiSciService baiSciService;

    /**
     * 查询每日科普列表
     */

    @GetMapping("/list")
    public TableDataInfo list(BaiSci baiSci)
    {
        startPage();
        List<BaiSci> list = baiSciService.selectBaiSciList(baiSci);
        return getDataTable(list);
    }

    /**
     * 导出每日科普列表
     */
    @RequiresPermissions("system:sci:export")
    @Log(title = "每日科普", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaiSci baiSci)
    {
        List<BaiSci> list = baiSciService.selectBaiSciList(baiSci);
        ExcelUtil<BaiSci> util = new ExcelUtil<BaiSci>(BaiSci.class);
        util.exportExcel(response, list, "每日科普数据");
    }

    /**
     * 获取每日科普详细信息
     */

    @GetMapping(value = "/content/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(baiSciService.selectBaiSciById(id));
    }

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo1(@PathVariable("id") Long id)
    {
        return success(baiSciService.selectBaiSciById(id));
    }

    /**
     * 获取上一条每日科普
     */

    @GetMapping(value = "/prev/{id}")
    public AjaxResult getPrev(@PathVariable("id") Long id)
    {
        return success(baiSciService.selectBaiSciPrevById(id));
    }

    /**
     * 获取上一条每日科普
     */

    @GetMapping(value = "/next/{id}")
    public AjaxResult getNext(@PathVariable("id") Long id)
    {
        return success(baiSciService.selectBaiSciNextById(id));
    }




    /**
     * 获取最新每日科普详细信息
     */

    @GetMapping(value = "/new")
    public AjaxResult getInfoNew()
    {
        return success(baiSciService.selectBaiSciNew());
    }

    /**
     * 新增每日科普
     */
    @RequiresPermissions("system:sci:add")
    @Log(title = "每日科普", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaiSci baiSci)
    {
        return toAjax(baiSciService.insertBaiSci(baiSci));
    }

    /**
     * 修改每日科普
     */
    @RequiresPermissions("system:sci:edit")
    @Log(title = "每日科普", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaiSci baiSci)
    {
        return toAjax(baiSciService.updateBaiSci(baiSci));
    }

    /**
     * 删除每日科普
     */
    @RequiresPermissions("system:sci:remove")
    @Log(title = "每日科普", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baiSciService.deleteBaiSciByIds(ids));
    }
//TAG_START:BaiSci_Top_list

// 控制器
@GetMapping("/top")
public TableDataInfo listTop(BaiSci baiSci) {
    startPage();
    List<BaiSci> list = baiSciService.selectBaiSciListTop(baiSci);
    return getDataTable(list);
}

//TAG_END:BaiSci_Top_list


}
